//
//  MyOperation.m
//  MultipleThreadDemo
//
//  Created by shuqiong on 16/6/7.
//  Copyright © 2016年 shuqiong. All rights reserved.
//

#import "MyOperation.h"

@interface MyOperation () {
    NSUInteger repeatCount;
}

@property (nonatomic, assign) OperateionState state;

@end

@implementation MyOperation

- (void)start {
    repeatCount = 0;
    if (!self.isCancelled) {
        [self willChangeValueForKey:@"isExecuting"];
        self.state = OperationStateExecuting;
        [self didChangeValueForKey:@"isExecuting"];
        
        for (int i = 0; i < 20; i++) {
            sleep(1);
            printf("name: ======%s state: %lu index: %d\n", [self.operationDes UTF8String], (unsigned long)self.state, i);
            if (!self.isCancelled) {
                printf("name: %s index: %d\n", [self.operationDes UTF8String], i);
            } else {
                break ;
            }
            if (i == 19) {
                [self willChangeValueForKey:@"isFinished"];
                self.state = OperationStateFinished;
                [self didChangeValueForKey:@"isFinished"];
            }
        }
    }
}

- (BOOL)isFinished {
    return self.state == OperationStateFinished;
}

- (BOOL)isExecuting {
    return self.state == OperationStateExecuting;
//    git@119.37.192.221:XiaoZhang.git
}

- (BOOL)isConcurrent {
    return YES;
}

@end
